﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuanLyPhongMach.HeThongXuLy_DTO;
using System.Data;

namespace QuanLyPhongMach.HeThongLuuTru_DAO
{
    class BenhNhanDAO
    {
        public static bool ThemBenhNhan(BenhNhanDTO bn)
        {
            try
            {
                //tao cau truy van va thuc thi cau truy van
                string sql = "insert into BenhNhan(HoTen, GioiTinh, NamSinh, DiaChi, NgayKham) values ('" +
                bn.HoTen + "','" +
                bn.GioiTinh + "','" +
                bn.NamSinh + "','" +
                bn.DiaChi + "','" +
                bn.NgayKham + "')";
                DataAccess.ExecNonQuery(sql);
                return true;
            }
                
            catch 
            {
                //MessageBox.Show(ex.ToString());
                return false;
            }
        }

        public static bool XoaBenhNhan(BenhNhanDTO bn)
        {
            try
            {
                //tao cau truy van va thuc thi cau truy van
                string sql = "delete from BenhNhan where MaBN=" + bn.MaBN;
                DataAccess.ExecNonQuery(sql);
                return true;
            }
            catch
            {
                //MessageBox.Show(ex.ToString());
                return false;
            }
        }

        public static bool SuaBenhNhan(BenhNhanDTO bn)
        {
            try
            {
                //tao cau truy van va thuc thi cau truy van
                string sql = "update BenhNhan set Hoten='" + bn.HoTen + "', GioiTinh='" + bn.GioiTinh + "', NamSinh='" + bn.NamSinh + "', DiaChi='" + bn.DiaChi + "', NgayKham='" + bn.NgayKham + "' where MaBN=" + bn.MaBN;
                DataAccess.ExecNonQuery(sql);
                return true;
            }
            catch
            {
                //MessageBox.Show(ex.ToString());
                return false;
            }
        }
        public static DataTable DanhSachBN()
        {
            string sql = "SELECT MaBN as [Mã bệnh nhân], HoTen as [Họ tên], GioiTinh as [Giới tính], NamSinh as [Năm sinh], DiaChi as [Địa chỉ], NgayKham as [Ngày khám] FROM BenhNhan";
            return DataAccess.ExecQuery(sql);
        }

        public static DataTable DanhSachBenh()
        {
            string sql = "SELECT * FROM Benh";
            return DataAccess.ExecQuery(sql);
        }

        public static DataTable DanhSachThuoc()
        {
            string sql = "SELECT * FROM Thuoc";
            return DataAccess.ExecQuery(sql);
        }

        public static DataTable DanhSachDonVi()
        {
            string sql = "SELECT * FROM DonVi";
            return DataAccess.ExecQuery(sql);
        }

        public static DataTable DanhSachCachDung()
        {
            string sql = "SELECT * FROM CachDung";
            return DataAccess.ExecQuery(sql);
        }
        //toathuoc
        

    }
}
